package com.linghang.association.controller;
import com.linghang.association.resp.CommonResp;
import com.linghang.association.service.MessageService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
/**
 * @author LinyaT052
 * @date 2022年07月21日 10:05
 * 实时消息推送控制层
 */
@RestController
@RequestMapping("/message")
public class MessageController {
    @Resource
    private MessageService messageService;
    /**
     * 消息推送接口,报名请求推送给管理员
     */
    @RequestMapping(value="/push-to-admin")
    public CommonResp pushToAdmin(Integer organizationId){
        CommonResp resp = new CommonResp();
        Map<String,Object>map = new HashMap<>();
        messageService.pushToAdmin(organizationId);
        map.put("code",200);
        map.put("msg","消息成功推送或已离线储存");
        map.put("status","success");
        resp.setContent(map);
        return resp;
    }
    /**
     * 消息推送接口,成功处理的报名请求推送给用户
     */
    @RequestMapping(value="/push-to-user")
    public CommonResp pushToUser(String username){
        CommonResp resp = new CommonResp();
        Map<String,Object>map = new HashMap<>();
        messageService.pushToUser(username);
        map.put("code",200);
        map.put("msg","消息成功推送或已离线储存");
        map.put("status","success");
        resp.setContent(map);
        return resp;
    }
    /**
     * 用户或者管理员上线应自动访问此接口
     * 判断是否有离线消息接口
     * 如果有直接发送
     */
    @RequestMapping("/offline-message")
    public CommonResp offlinePush(String username){
        CommonResp resp = new CommonResp();
        Map<String,Object>map = new HashMap<>();
        int size = messageService.offlinePush(username);
        map.put("size",size);
        map.put("status","success");
        resp.setContent(map);
        return resp;
    }

}
